import requests

from api.ihrm_login_api import IhrmLoginApi


class IhrmDepApi(object):

    @classmethod  # 添加部门
    def add_dep(cls, req_header, req_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/company/department",
                             headers=req_header, json=req_data)
        return resp

    @classmethod  # 查询部门
    def query_dep(cls, dep_id, req_header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/company/department/" + dep_id,
                            headers=req_header)
        return resp

    @classmethod  # 修改部门
    def modify_dep(cls, dep_id, req_header, req_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/company/department/" + dep_id,
                            headers=req_header, json=req_data)
        return resp

    @classmethod  # 删除部门
    def delete_dep(cls, dep_id, req_header):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/company/department/" + dep_id,
                               headers=req_header)
        return resp


if __name__ == '__main__':
    data = {"mobile": "13800000002", "password": "123456"}
    resp = IhrmLoginApi.login(data)
    token = resp.json().get("data")
    req_data = {"name": "尊宝阿是啊吧", "code": "9527676767"}
    req_header = {"Authorization": f"{token}"}
    dep_id = "1495045644891496448"
    # resp = IhrmDepApi.add_dep(req_header, req_data)
    # resp = IhrmDepApi.query_dep(dep_id, req_header)
    resp = IhrmDepApi.modify_dep(dep_id, req_header, req_data)
    # resp = IhrmDepApi.delete_dep(dep_id, req_header)
    print(resp.json())
